package ro.gillardon.persistence.document.model;

import java.time.LocalDateTime;

import ro.gillardon.commons.enums.City;
import ro.gillardon.commons.mot.MotClass;

import com.orientechnologies.orient.core.record.impl.ODocument;

/**
 * Abstract class which contains methods and details specific to a mean of transport.
 *
 * @author haiurar
 */
public abstract class Mot extends ODocumentClass {

  private static final String PRICE = "price";
  private static final String CLASS = "class";
  private static final String DURATION = "duration";
  private static final String NAME = "name";
  private static final String ARRIVAL_DATETIME = "arrivalDatetime";
  private static final String DEPARTURE_DATETIME = "departureDatetime";
  private static final String TO = "to";
  private static final String FROM = "from";

  /**
   * Instantiates a new Mot.
   *
   * @param from the starting point
   * @param to the destination
   * @param departureDatetime the departure date and time
   * @param arrivalDatetime the arrival date and time
   * @param name the company name
   * @param duration the duration of the travel
   * @param motClass the class of the mean of transport
   * @param price the price of the travel
   */
  protected Mot(final City from, final City to, final LocalDateTime departureDatetime,
    final LocalDateTime arrivalDatetime, final String name,
    final double duration, final double price) {
    super();
    this.doc.field(FROM, from);
    this.doc.field(TO, to);
    this.doc.field(DEPARTURE_DATETIME, departureDatetime);
    this.doc.field(ARRIVAL_DATETIME, arrivalDatetime);
    this.doc.field(NAME, name);
    this.doc.field(DURATION, duration);
    this.doc.field(PRICE, price);
  }

  public void setMotClass(final MotClass motClass) {
    this.doc.field(CLASS, motClass);
  }

  /**
   * Instantiates a new Mot.
   *
   * @param doc the document which contains informations
   */
  public Mot(final ODocument doc) {
    this.doc = doc;
  }

  /**
   * Gets the starting point.
   *
   * @return the starting city
   */
  public City getFrom() {
    return this.doc.field(FROM);
  }

  /**
   * Gets the destination.
   *
   * @return the destination city
   */
  public City getTo() {
    return this.doc.field(TO);
  }

  /**
   * Gets the departure date.
   *
   * @return the departure date
   */
  public LocalDateTime getDepartureDatetime() {
    return this.doc.field(DEPARTURE_DATETIME);
  }

  /**
   * Gets the arrival date.
   *
   * @return the arrival date
   */
  public LocalDateTime getArrivalDatetime() {
    return this.doc.field(ARRIVAL_DATETIME);
  }

  /**
   * Gets the name of the company.
   *
   * @return the name of the company
   */
  public String getName() {
    return this.doc.field(NAME);
  }

  /**
   * Gets the duration of the travel.
   *
   * @return the duration of the travel
   */
  public double getDuration() {
    return this.doc.field(DURATION);
  }

  /**
   * Gets the class of the mean of transport.
   *
   * @return the class of the mean of transport
   */
  public MotClass getMotClass() {
    return this.doc.field(CLASS);
  }

  /**
   * Gets the price.
   *
   * @return the price
   */
  public double getPrice() {
    return this.doc.field(PRICE);
  }
}
